package com.pkk.penguin.frame.know.java.driven.beanleftcycle.bean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: 一个bean
 * @author: peikunkun
 * @create: 2020-08-04 11:17
 **/
@Slf4j
public class BeanLeftCycleBean2 {

  public BeanLeftCycleBean2() {
    System.out.println(this.getClass().getSimpleName() + "【构造器】  Constructor ...");
  }


  /**
   * @Description: 容器销毁之前的操作
   * @return: void
   * @Author: peikunkun
   * @Date: 2020/8/4 0004 上午 11:47
   */
  @PreDestroy
  public void destroy() throws Exception {
    System.out.println(this.getClass().getSimpleName() + " 【@PreDestroy】 destory ...");
  }

  /**
   * The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to
   * perform any initialization. This method MUST be invoked before the class is put into service. This annotation MUST
   * be supported on all classes that support dependency injection. The method annotated with PostConstruct MUST be
   * invoked even if the class does not request any resources to be injected. Only one method can be annotated with this
   * annotation. The method on which the PostConstruct annotation is applied MUST fulfill all of the following
   * criteria:
   * <p>
   * <ul>
   * <li>The method MUST NOT have any parameters except in the case of
   * interceptors in which case it takes an InvocationContext object as
   * defined by the Interceptors specification.</li>
   * <li>The method defined on an interceptor class MUST HAVE one of the
   * following signatures:
   * <p>
   * void &#060;METHOD&#062;(InvocationContext)
   * <p>
   * Object &#060;METHOD&#062;(InvocationContext) throws Exception
   * <p>
   * <i>Note: A PostConstruct interceptor method must not throw application
   * exceptions, but it may be declared to throw checked exceptions including
   * the java.lang.Exception if the same interceptor method interposes on
   * business or timeout methods in addition to lifecycle events. If a
   * PostConstruct interceptor method returns a value, it is ignored by
   * the container.</i>
   * </li>
   * <li>The method defined on a non-interceptor class MUST HAVE the
   * following signature:
   * <p>
   * void &#060;METHOD&#062;()
   * </li>
   * <li>The method on which PostConstruct is applied MAY be public, protected,
   * package private or private.</li>
   * <li>The method MUST NOT be static except for the application client.</li>
   * <li>The method MAY be final.</li>
   * <li>If the method throws an unchecked exception the class MUST NOT be put into
   * service except in the case of EJBs where the EJB can handle exceptions and
   * even recover from them.</li></ul>
   *
   * @see javax.annotation.PreDestroy
   * @see javax.annotation.Resource
   * @since Common Annotations 1.0
   */
  /**
   * 构造器对象创建并赋值之后操作
   */
  @PostConstruct
  public void init() throws Exception {
    System.out.println(this.getClass().getSimpleName() + "  【@PostConstruct】 init ...");
  }
}
